package class01;


public class StringBufferTest {
    public static void main(String[] args) {
//        StringBuffer sb = new StringBuffer();
        StringBuilder sb = new StringBuilder();
//       （1）StringBuffer append(xx)：提供了很多的append()方法，用于进行字符串追加的方式拼接
//        StringBuffer append = sb.append("大数据5班");
        StringBuilder append = sb.append("大数据5班");

        System.out.println(append);
//（2）StringBuffer delete(int start, int end)：删除[start,end)之间字符
//        StringBuffer delete = append.delete(3, 4);
        StringBuilder delete = append.delete(3, 4);
        System.out.println(delete);

//（3）StringBuffer deleteCharAt(int index)：删除[index]位置字符
        System.out.println(delete.deleteCharAt(2));
//（4）StringBuffer replace(int start, int end, String str)：替换[start,end)范围的字符序列为str
//        StringBuffer replace = append.replace(3, 6, "6班");
        StringBuilder replace = append.replace(3, 6, "6班");
        System.out.println(replace);

//（5）void setCharAt(int index, char c)：替换[index]位置字符
        replace.setCharAt(2, '据');
        System.out.println(replace);

//（6）char charAt(int index)：查找指定index位置上的字符
        System.out.println(replace.charAt(2));
//（7）StringBuffer insert(int index, xx)：在[index]位置插入xx
        replace.insert(3, '5');
        System.out.println(replace);
//（8）int length()：返回存储的字符数据的长度
        System.out.println(replace.length());
//（9）StringBuffer reverse()：反转
        System.out.println(replace.reverse());
    }
}
